import { ElMessageBox } from 'element-plus'

export const deleteCommonFnc = async (callbackCustom: any, item: any, config: any = {}) => {
  let confirmTemp = {
    tip: '您确定要删除该数据吗？',
    title: '提示',
    confirmButtonText: '确认',
    cancelButtonText: '取消',
    type: 'warning'
  }
  config = Object.assign(confirmTemp, config) // 有什么字段，覆盖什么什么字段。
  const result = await ElMessageBox.confirm(config.tip, config.title, {
    confirmButtonText: config.confirmButtonText,
    cancelButtonText: config.cancelButtonText,
    type: config.type
  }).catch(err => err)

  console.log('message的result：', result)
  if (result == 'confirm') {
    callbackCustom(item)
  }
}

export const transformDict = (dictObj: any) => {
  let arr: any[] = []
  for (let key in dictObj) {
    arr.push({
      label: key,
      value: dictObj[key]
    })
  }
  return arr || []
}

export const transformDictName = (value: any, list: any) => {
  let name = ''
  list.forEach((v: any) => {
    if (value == v.value) {
      name = v.label
    }
  })
  return name || ''
}

export function isEmptyStr(value: string) {
  if (value == null || value === '') {
    return true
  }
  return false
}
